// @ts-ignore
import Login from './login/login.tsx'
import React from 'react'
import ReactDOM from 'react-dom'
import "./index.scss"
import store, { StoreContext } from './store/store'
import { CSSTransition, SwitchTransition } from 'react-transition-group'
import { loginCheck } from './login/login'
import { initialize } from './initial'
import { Home } from './home'
class App extends React.Component<any, any> {
    constructor(props:any) {
        super(props);
        this.state = {
            logined: loginCheck(),
            setLogined: this.setLogined,
            store: {},
            setStore: this.setStore,
        }
        // 如果已经登录则自动执行初始化过程。
        if (this.state.logined) {
            initialize().then(() => {
                this.setStore(store)
            })
        }
    }
    setLogined = (status: boolean) => {
        this.setState({logined: status})
    }
    setStore = (store: any) => {
        this.setState({store})
    }
    testF = () => {
        this.setState({logined: !this.state.logined})
    }
    render() {
        try {
            return (
                <StoreContext.Provider value={this.state}>
                    <div className="st-container">
                        <SwitchTransition mode="out-in">
                            <CSSTransition classNames={"st_ani"} className="st_ani" key={this.state.logined ? "on" : "off"} timeout={1000}>
                                {this.state.logined ? <Home/> : <Login/>}
                            </CSSTransition>
                        </SwitchTransition>
                    </div>
                </StoreContext.Provider>
            )
        } catch (e) {
            return <div>err: {e.message}</div>
        }
    }
}
ReactDOM.render(<App/>, document.getElementById("ourintegral"))